import Vue from "vue";
import Vuex from "vuex";
import { goodsList } from "@/request/api";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    popShow: false,
    popGoodList: [],
    blockShow:2,
    filterCategory:[],
    upPage:''
  },
  mutations: {
    changePopShow(state, payload) {
      state.popShow = payload
    },
    changeupPage(state, payload) {
      state.upPage = payload
    },
    // 修改搜索数据
    changePopGoodList(state, payload) {
      state.popGoodList = payload
    },
    // 修改显示数据
    changeBlockShow(state, payload) {
      state.blockShow = payload
    }
  },
  actions: {
    // 异步请求数据
    AsyncChangePopGoodList({commit,rootState},payload){
      goodsList({
        keyword:payload.keyword,
        categoryId:payload.categoryId,
        order:payload.order,
        sort:payload.sort
      }).then(res=>{
        rootState.popGoodList = res.data.goodsList
        var arr = JSON.parse(JSON.stringify(res.data.filterCategory).replace(/name/g, 'text'))
        rootState.filterCategory = arr
      })
    }
  },
  modules: {},
});
